package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.Announcement;
import com.tanhua.domain.vo.PageResult;
import com.tanhua.dubbo.mapper.AnnouncementMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 消息--公告
 */
@Service
public class AnnouncementApiImpl implements AnnouncementApi {
    //订阅 AnnouncementMapper
    @Autowired
    private AnnouncementMapper announcementMapper;
    /**
     * 公告
     * @param page 当前页码
     * @param pagesize 每页条数
     * @return
     */
    @Override
    public PageResult<Announcement> Pageannouncements(Long page, Long pagesize) {

        //构建分页对象
        Page<Announcement> pages = new Page<>(page,pagesize);
        IPage<Announcement> pageInfo = announcementMapper.selectPage(pages, new QueryWrapper<>());
        //构建 pageResult
        PageResult<Announcement> pageResult = new PageResult<>();
        pageResult.setItems(pageInfo.getRecords());//当前页集合数据
        pageResult.setPage(page);
        pageResult.setPagesize(pagesize);
        pageResult.setCounts(pageInfo.getTotal()); //总记录数
        pageResult.setPages(pageInfo.getPages());//总页数
        return pageResult;
    }
}
